package skipass.command;

import java.util.Calendar;

import skipass.CardStatSystem;
import skipass.container.DayCard;

public class CheckDay implements Command {

	private DayCard card;
	private CardStatSystem css;

	public CheckDay(DayCard card, CardStatSystem css) {
		this.card = card;
		this.css = css;
	}

	@Override
	public boolean execute() {
		Calendar cur = css.getCurrentTime();
		int dayCount = card.getDays();
		if (dayCount > 0) {			
			Calendar lastDay = card.getLastDay();
			if (lastDay == null) {				
				card.setLastDay((Calendar) cur.clone());
				card.setDays(dayCount - 1);
				return true;
			} else {
				if (cur.get(Calendar.DAY_OF_YEAR) > lastDay.get(Calendar.DAY_OF_YEAR) 
						|| cur.get(Calendar.YEAR) > lastDay.get(Calendar.YEAR)) {
					card.setDays(dayCount - 1);
					return true;
				}
				else return true;
			}
		}
		else return false;
	}

}
